<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="积分时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="等级" :labelCol="{span:3}" :wrapperCol="{span:21}" prop="classess">
              <j-dict-select-tag type="list" v-model="model.classess" dictCode="TYSX_CLASSESS" placeholder="请选择等级"  @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="奖项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="award">
              <j-dict-select-tag type="list" v-model="model.award" dictCode="TYSX_AWARD" placeholder="请选择奖项" @change="getTotalScore" />
            </a-form-model-item>
          </a-col>
          <a-col :span="16" >
            <a-form-model-item label="赛项名称" :labelCol="{span:3}" :wrapperCol="{span:21}" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入赛项名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 16 }" prop="totalScore">
              <a-input v-model="model.totalScore" placeholder="请输入名称" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model" :disabled="formDisabled" :loading="memberListTable.loading"></member-list>

  </a-spin>
</template>

<script>

  import { getAction } from '@/api/manage'
  import { FormTypes,getRefPromise,VALIDATE_NO_PASSED } from '@/utils/JEditableTableUtil'
  import { JEditableTableModelMixin } from '@/mixins/JEditableTableModelMixin'
  import { validateDuplicateValue } from '@/utils/util'
  import { GfxyMemberListMixin } from '@/mixins/GfxyMemberListMixin'
  import GYearPicker from '@views/gfxy/common/GYearPicker'
  import MemberList from '@views/gfxy/common/memberList'
  import moment from 'moment'

  export default {
    name: 'TysxForm',
    mixins: [GfxyMemberListMixin],
    components: {
      GYearPicker,MemberList
    },
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        validatorRules: {
           year: [
              { required: true, message: '请输入时间!'},
           ],
           classess: [
              { required: true, message: '请输入等级!'},
           ],
           award: [
              { required: true, message: '请输入奖项!'},
           ],
           projectName: [
              { required: true, message: '请输入赛项名称!'},
           ],
        },
        url: {
          add: "/teaching/tysx/add",
          edit: "/teaching/tysx/edit",
          queryById: "/teaching/tysx/queryById",
          getTotalScore: "teaching/tysx/getTotalScore",
          memberList: {
            list: '/teaching/tysx/queryMemberListByMainId'
          },
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      itemValue:{
        type: Number,
        required: true,
      },
      date:{
        type: String,
        required: true,
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
    },
    methods: {
      getTotalScore(){

        if(this.model.award != undefined && this.model.classess != undefined){
          this.confirmLoading = true;
          getAction(this.url.getTotalScore,{classess: this.model.classess, award: this.model.award}).then((res) => {
            if (res.success) {
              this.model.totalScore = res.result;
              this.$nextTick(()=>{
                this.$refs.memberListRef.getScore();
              })
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
            this.confirmLoading = false;
          })
        }
      }
    }
  }
</script>

<style scoped>
</style>